home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8448 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  55 lines

  1. Path: isonews.bbn.hp.com!hpbblb!news
  2. From: Matthias Dittrich <matti>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: strange behaviour of doubles
  5. Date: 4 Mar 1996 12:46:25 GMT
  6. Organization: Hewlett-Packard Co.
  7. Message-ID: <4heon1$6q7@hpbblb.bbn.hp.com>
  8. References: <1996Mar4.014052.6236@dcs.warwick.ac.uk>
  9. NNTP-Posting-Host: trabant.bbn.hp.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/712)
  14. X-URL: news:1996Mar4.014052.6236@dcs.warwick.ac.uk
  15.  
  16. D.C.Molero@dcs.warwick.ac.uk (Daniel Castillo Molero) wrote:
  17. >
  18. >Dear readers,
  19. >Can anybody explain to me why the behaviour of the following little
  20. >program is not the expected one ??
  21. >It is supposed to read from std input pairs of doubles and print them,
  22. >until 0.0 is input.
  23. >The strange thing is that it doesn't print the input number, e.g. when
  24. >I input 1.0 1.0   it prints   0.0078125  0.0078125
  25. >I will appreciate very much any help.
  26. >
  27. >
  28. >#include <stdio.h>
  29. >#include <stdlib.h>
  30. >
  31. >main() {
  32. >double x, y;
  33. >scanf("%g", &x);
  34. >while (x != 0.0) {
  35. >  scanf("%g", &y);
  36. Use format "%lg" because you have specified to read a float here !!
  37.  
  38. >  printf("%g %g\n", x, y);
  39. If you are printing before reading in the value of x, there is an undefined
  40. value on the stack.
  41.  
  42. >  scanf("%g", &x);
  43. Format see above.
  44.  
  45. >}
  46. >return(0);
  47. >}
  48. >-- 
  49. >* Daniel Castillo.  danmol@dcs.warwick.ac.uk *
  50. >
  51. >
  52. Good luck,
  53. Matthias
  54.  
  55.